/****************************************************************
 * Fulguro
 * Copyright (C) 2004 Christophe Clienti
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 ***************************************************************/

/*********************** Documentation ***********************/



%{
#if defined(SWIGPYTHON)
  static PyObject *flgr_nhb_callback = NULL;
  
  void flgr_set_nhb_callback(PyObject *temp) {
    if (!PyCallable_Check(temp)) {
      PyErr_SetString(PyExc_TypeError, "parameter must be callable");
      return;
    }
    //Py_XINCREF(temp);         /* Add a reference to new callback */
    //Py_XDECREF(flgr_nhb_callback);  /* Dispose of previous callback */
    flgr_nhb_callback = temp;       /* Remember new callback */
  }

  void function_shell_getNhb_1d(FLGR_Vector *result, FLGR_NhbBox1D *extr) {
    PyObject *arglist;
    PyObject *SWIG_Result;
    PyObject *SWIG_Extr;
   
   if(result->spp != extr->spp) return;

     /* Time to call the callback */
    SWIG_Result  = SWIG_NewPointerObj(result,SWIGTYPE_p_FLGR_Vector, 0 | 0);
    SWIG_Extr = SWIG_NewPointerObj(extr,SWIGTYPE_p_FLGR_NhbBox1D, 0 | 0);
    
    arglist   = Py_BuildValue("OO", SWIG_Result, SWIG_Extr);

    PyEval_CallObject(flgr_nhb_callback, arglist);
    Py_DECREF(arglist);
  }

  void function_shell_getNhb_2d(FLGR_Vector *result, FLGR_NhbBox2D *extr) {
    PyObject *arglist;
    PyObject *SWIG_Result;
    PyObject *SWIG_Extr;
   
   if(result->spp != extr->spp) return;

     /* Time to call the callback */
    SWIG_Result  = SWIG_NewPointerObj(result,SWIGTYPE_p_FLGR_Vector, 0 | 0);
    SWIG_Extr = SWIG_NewPointerObj(extr,SWIGTYPE_p_FLGR_NhbBox2D, 0 | 0);
    
    arglist   = Py_BuildValue("OO", SWIG_Result, SWIG_Extr);

    PyEval_CallObject(flgr_nhb_callback, arglist);
    Py_DECREF(arglist);
  }



#elif defined(SWIGRUBY)
  static VALUE flgr_nhb_callback = Qnil;
 
  void flgr_set_nhb_callback(VALUE temp) {
    flgr_nhb_callback = temp;
  }

  void function_shell_getNhb_1d(FLGR_Vector *result, FLGR_NhbBox1D *extr) {
    VALUE SWIG_Result;
    VALUE SWIG_Extr;
   
    if(result->spp != extr->spp) return;

    /* Time to call the callback */
    SWIG_Result  = SWIG_NewPointerObj(result,SWIGTYPE_p_FLGR_Vector, 0 |  0);
    SWIG_Extr = SWIG_NewPointerObj(extr,SWIGTYPE_p_FLGR_NhbBox1D, 0 |  0);
    rb_funcall(flgr_nhb_callback,rb_intern("call"),2,SWIG_Result,SWIG_Extr);

  }

 void function_shell_getNhb_2d(FLGR_Vector *result, FLGR_NhbBox2D *extr) {
    VALUE SWIG_Result;
    VALUE SWIG_Extr;
   
    if(result->spp != extr->spp) return;

    /* Time to call the callback */
    SWIG_Result  = SWIG_NewPointerObj(result,SWIGTYPE_p_FLGR_Vector, 0 |  0);
    SWIG_Extr = SWIG_NewPointerObj(extr,SWIGTYPE_p_FLGR_NhbBox2D, 0 |  0);
    rb_funcall(flgr_nhb_callback,rb_intern("call"),2,SWIG_Result,SWIG_Extr);

  }


#else

#error "No support for this language"

#endif


%}






typedef void (*FLGR_ComputeNhb1D)    (FLGR_Vector *result, FLGR_NhbBox1D *extr); 

%typemap(in) (FLGR_ComputeNhb1D) {
  flgr_set_nhb_callback($input);
  $1 = function_shell_getNhb_1d;
 }

%typecheck(SWIG_TYPECHECK_POINTER) FLGR_ComputeNhb1D {
  $1=1;
 }






typedef void (*FLGR_ComputeNhb2D)    (FLGR_Vector *result, FLGR_NhbBox2D *extr); 

%typemap(in) (FLGR_ComputeNhb2D) {
  flgr_set_nhb_callback($input);
  $1 = function_shell_getNhb_2d;
 }

%typecheck(SWIG_TYPECHECK_POINTER) FLGR_ComputeNhb2D {
  $1=1;
 }







%feature("autodoc","""
[out] FLGR_Data1D destination
[in]  FLGR_Data1D source
[in]  FLGR_Data1D nhb definition
[in]  Integer flag to symetrize or not nhb (FLGR_NHB_NO_SYM, FLGR_NHB_SYM)
[in]  Function to process neighborhood
[return] FLGR_Ret\n
Extract structuring elements for each pixels and execute the given neighborhood function
""") flgr1d_raster_slide_window;
FLGR_Ret flgr1d_raster_slide_window(FLGR_Data1D *imgdest,FLGR_Data1D *imgsrc,FLGR_Data1D *nhb,
				    int nhb_sym,FLGR_ComputeNhb1D getNhbVal);

%feature("autodoc","""
[out] FLGR_Data1D destination
[in]  FLGR_Data1D source
[in]  FLGR_Data1D nhb definition
[in]  Integer flag to symetrize or not nhb (FLGR_NHB_NO_SYM, FLGR_NHB_SYM)
[in]  Function to process neighborhood
[return] FLGR_Ret\n
Extract structuring elements for each pixels and execute the given neighborhood function. Border are processed
as the data was unfolded on border.
""") flgr1d_raster_slide_window_unfolded;
FLGR_Ret flgr1d_raster_slide_window_unfolded(FLGR_Data1D *imgdest,FLGR_Data1D *imgsrc,FLGR_Data1D *nhb,
					     int nhb_sym,FLGR_ComputeNhb1D getNhbVal);


%feature("autodoc","""
[out] FLGR_Data1D destination
[in]  FLGR_Data1D source
[in]  FLGR_Data1D nhb definition
[in]  Integer flag to symetrize or not nhb (FLGR_NHB_NO_SYM, FLGR_NHB_SYM)
[in]  Function to process neighborhood
[return] FLGR_Ret\n
Extract structuring elements for each pixels and execute the given neighborhood function
""") flgr1d_anti_raster_slide_window;
FLGR_Ret flgr1d_anti_raster_slide_window(FLGR_Data1D *imgdest,FLGR_Data1D *imgsrc,FLGR_Data1D *nhb,
					 int nhb_sym,FLGR_ComputeNhb1D getNhbVal);

%feature("autodoc","""
[out] FLGR_Data1D destination
[in]  FLGR_Data1D source
[in]  FLGR_Data1D nhb definition
[in]  Integer flag to symetrize or not nhb (FLGR_NHB_NO_SYM, FLGR_NHB_SYM)
[in]  Function to process neighborhood
[return] FLGR_Ret\n
Extract structuring elements for each pixels and execute the given neighborhood function Border are processed
as the data was unfolded on border.
""") flgr1d_anti_raster_slide_window_unfolded;
FLGR_Ret flgr1d_anti_raster_slide_window_unfolded(FLGR_Data1D *imgdest,FLGR_Data1D *imgsrc,FLGR_Data1D *nhb,
						  int nhb_sym,FLGR_ComputeNhb1D getNhbVal);


%feature("autodoc","""
[out] FLGR_Data2D destination
[in]  FLGR_Data2D source
[in]  FLGR_Data2D nhb definition
[in]  Integer flag to symetrize or not nhb (FLGR_NHB_NO_SYM, FLGR_NHB_SYM)
[in]  Function to process neighborhood
[return] FLGR_Ret\n
Extract structuring elements for each pixels and execute the given neighborhood function
""") flgr2d_raster_slide_window;
FLGR_Ret flgr2d_raster_slide_window(FLGR_Data2D *imgdest,FLGR_Data2D *imgsrc,FLGR_Data2D *nhb,
				    int nhb_sym,FLGR_ComputeNhb2D getNhbVal);

%feature("autodoc","""
[out] FLGR_Data2D destination
[in]  FLGR_Data2D source
[in]  FLGR_Data2D nhb definition
[in]  Integer flag to symetrize or not nhb (FLGR_NHB_NO_SYM, FLGR_NHB_SYM)
[in]  Function to process neighborhood
[return] FLGR_Ret\n
Extract structuring elements for each pixels and execute the given neighborhood function. Border are processed
as the data was unfolded on border.
""") flgr2d_raster_slide_window_unfolded;
FLGR_Ret flgr2d_raster_slide_window_unfolded(FLGR_Data2D *imgdest,FLGR_Data2D *imgsrc,FLGR_Data2D *nhb,
					     int nhb_sym,FLGR_ComputeNhb2D getNhbVal);


%feature("autodoc","""
[out] FLGR_Data2D destination
[in]  FLGR_Data2D source
[in]  FLGR_Data2D nhb definition
[in]  Integer flag to symetrize or not nhb (FLGR_NHB_NO_SYM, FLGR_NHB_SYM)
[in]  Function to process neighborhood
[return] FLGR_Ret\n
Extract structuring elements for each pixels and execute the given neighborhood function
""") flgr2d_anti_raster_slide_window;
FLGR_Ret flgr2d_anti_raster_slide_window(FLGR_Data2D *imgdest,FLGR_Data2D *imgsrc,FLGR_Data2D *nhb,
					 int nhb_sym,FLGR_ComputeNhb2D getNhbVal);

%feature("autodoc","""
[out] FLGR_Data2D destination
[in]  FLGR_Data2D source
[in]  FLGR_Data2D nhb definition
[in]  Integer flag to symetrize or not nhb (FLGR_NHB_NO_SYM, FLGR_NHB_SYM)
[in]  Function to process neighborhood
[return] FLGR_Ret\n
Extract structuring elements for each pixels and execute the given neighborhood function Border are processed
as the data was unfolded on border.
""") flgr2d_anti_raster_slide_window_unfolded;
FLGR_Ret flgr2d_anti_raster_slide_window_unfolded(FLGR_Data2D *imgdest,FLGR_Data2D *imgsrc,FLGR_Data2D *nhb,
						  int nhb_sym,FLGR_ComputeNhb2D getNhbVal);








%feature("autodoc","""
[out] FLGR_Data1D destination
[in]  FLGR_Data1D source
[in]  FLGR_Data1D semap containing nhb informations (spp=1,2 or 3) for each source values (FLGR_INT32)
[in]  FLGR_Shape shape to use
[in]  Function to process neighborhood
Compute filter with resizable structuring element.
 
   SE width for each pixel are stored in semap. semap could have one to three channel
 
   - If semap.spp==1 then 
       - Channel 1 indicates the width of the square around the shape
 
   - If semap.spp==2 then  
       - Channel 1 indicates the width of the rectangle around the shape
       - Channel 2 indicates the height of the rectangle around the shape
 
   - If semap.spp==3 then  
       - Channel 1 indicates the width of the rectangle around the shape
       - Channel 2 indicates the height of the rectangle around the shape
       - Channel 3 indicates the rotation angle of the shape [-180,180] degrees
 
""") flgr2d_raster_slide_structuring_function;
FLGR_Ret flgr2d_raster_slide_structuring_function(FLGR_Data2D *datdest, FLGR_Data2D *datsrc, 
						  FLGR_Data2D *semap, FLGR_Shape shape, 
						  FLGR_ComputeNhb2D computeNhb);
